package com.sunfeng.n8.concurrenthashmap;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * concurrent
 *
 * @author sunfeng
 * @date 2021/04/22 17:17
 **/


public class Test1 {

    static final String ALPHA = "abcedfghijklmnopqrstuvwxyz";

    public static void main(String[] args) throws IOException {

        int length = ALPHA.length();
        int count = 200;
        List<String> list = new ArrayList<>(length * count);
        for (int i = 0; i < length; i++) {
            char ch = ALPHA.charAt(i);
            for (int j = 0; j < count; j++) {
                list.add(String.valueOf(ch));
            }
        }
        Collections.shuffle(list);
        for (int i = 0; i < 26; i++) {

            File file = new File("F:\\03_study\\concurrent\\tmp\\" + (i + 1) + ".txt");

            if (!file.exists()) {
                file.createNewFile();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            FileChannel channel = fileOutputStream.getChannel();

            String collect = list.subList(i * count, (i + 1) * count).stream()
                    .collect(Collectors.joining("\n"));
            channel.write(ByteBuffer.wrap(collect.getBytes(StandardCharsets.UTF_8)));
        }

    }
}
